<template>
  <div>
    <button @click="$emit('back')">返回</button>
    <form @submit.prevent="submitForm" class="form">
      <div>Env ID: {{ envId }}</div>
      <div>
        <label>并行计算任务配置:</label>
        <input type="file" @change="onParallelFileChange" required />
      </div>
      <div>
        <label>聚合计算任务配置:</label>
        <input type="file" @change="onAggregateFileChange" />
      </div>
      <button type="submit">Submit</button>
    </form>
  </div>
</template>

<script>
import { submitJob } from '../api';

export default {
  props: ['envId'],
  data() {
    return {
      parallelFile: null,
      aggregateFile: null,
    };
  },
  methods: {
    onParallelFileChange(e) {
      this.parallelFile = e.target.files[0];
    },
    onAggregateFileChange(e) {
      this.aggregateFile = e.target.files[0];
    },
    async submitForm() {
      const formData = new FormData();
      formData.append('parallel_config', this.parallelFile);
      if (this.aggregateFile) formData.append('aggregate_config', this.aggregateFile);
      await submitJob(formData);
      this.$emit('back');
    },
  },
};
</script>

<style scoped>
.form {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 20px;
}
div {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
label {
  flex: 1;
}
input[type="file"] {
  flex: 2;
}
button {
  padding: 8px 16px;
}
</style>
